<?php
	/**
	 * <version greek="beta" major="1" minor="0">Cochin Splash Hen</version>
	 * <author email="njones@art-k-tec.com">Nika Jones</author>
	 * <copyright start="2007">Art-k-tec Systems, LLC</copyright>
	 * <license type="Apache2.0" href="http://www.opensource.org/licenses/apache2.0.php">Apache License, Version 2.0</license>
	 */
	
	/**
	* <summary>All of the exception constants for this class.</summary>
	*/
	class bXmlException extends Exception {
		const INVALID_CONVERSION 				=10001;
		const INVALID_CONVERSION_ARRAY 			=10000;
		const INVALID_CONVERSION_STRING 		=10000;
		const INVALID_STRING_XML		 		=10000;
		const INVALID_PERMISSIONS				=10000;
		const INVALID_CONSTRUCTOR				=10000;
		
		const NOT_bXML							=10000;
		const NOT_LOADED						=10000;
	}
	
	/**
	 * <summary>
	 * 	Basically a type that covers both bXml and bSimpleXml
	 * </summary>
	 */
	interface IbXml {}
	
	 /**
	 * <summary>
	 * 	Takes the simplexml core and extends a bit
	 * </summary>
	 */
	class bSimpleXml extends SimpleXmlElement implements IbXml{
		private static $nMajor =1;
		private static $nMinor =0;
		private static $sRevision ="0000";
		
		public static function version() { return self::$nMajor.'.'.self::$nMinor.'.'.self::$sRevision; }
		
		/// <summary>
		///   Gets the namespaces of the current document/node, and any passed in node,
		///   and adds to the current document/node
		/// </summary>
		/// <returns type="array">
		///   All of the namespace uris and prefixes within the document/node
		/// </returns>
		private function ObjectNamespace($oNode =null) {
			static $aNameSpace =array();
			static $n =0;
			
			$oNode =($oNode ==null ? $this : $oNode);
			$aDocNameSpace =$oNode->getNamespaces();
			
			$a =array_diff($aDocNameSpace, array_flip($aNameSpace));
			
			foreach($a as $sNamespace) {
				$ns ='ns'.$n++;
				$this->registerXPathNamespace($ns, $sNamespace);
				$aNameSpace[$sNamespace] =$ns;
				
			}
			
			return $aNameSpace;
		}
		
		/// <summary>
		/// 	Holds the single XSLT processor for efficacy reasons
		/// </summary>
		/// <returns type="XsltProcessor" />
		private function ObjectProcessor() {
			static $oProcessor =null;
			
			if($oProcessor ==null) {
				
				// Current behavior is that imported stylesheets will override oneanother
				// so we can just fire up one instance of this and keep using.
				$oProcessor =new XsltProcessor();
			}
			
			return $oProcessor;
		}
		
		/// <summary>
		/// 	Handles the loading of the stylesheet to the processor. Mantains only one processor
		/// 	for all bXml objects (it's static)
		/// </summary>
		/// <param type="bXml" name="xXsl" byreference="true">The XSLT stylesheetL</param>
		/// <param type="array" name="aArgument" optional="true">The argument data to add to the stylesheet</param>
		private function LoadStylesheet(bXml $xXsl, array $aArgument =null) {

			if(is_array($aArgument)) {
				foreach($aArgument as $aNamespaceKeyValue) {
					list($sNamespace, $sKey, $sValue) = $aNamespaceKeyValue;
 					$this->ObjectProcessor()->setParameter($sNamespace, $sKey, $sValue);
				}
			}
			
			$this->ObjectProcessor()->importStylesheet($xXsl->AsDom());
			unset($xXsl);
		}
		
		/// <summary>
		/// 	Allows the addition of a CDATA node
		/// </summary>
		/// <param type="string" name="sData">Any string</param>
		/// <returns type="this" />
		public function AddCData($sData) {

			$oNode =dom_import_simplexml($this);
			$oDom =$oNode->ownerDocument;
			
			$oCData =$oDom->createCDATASection($sData);
			$oNode->appendChild($oCData);
			
			return $this;
		}
		
		/// <summary>
		/// 	Overwrites the Addchild to allow things like adding string XML into the child location
		/// </summary>
		/// <param type="mixed" name="sName">
		public function AddChild($mName, $mData =null, $sNamespace =null) {
			// sniff to see if $sName is really Xml
			if(is_string($mName)) {
				
				if(!preg_match('/[\/<]/', $mName)) { // not a valid qname... so check for xml
					
					parent::AddChild($mName, $mData, $sNamespace);
					return $this;
				}
			}
			
			if($mData ==null) { 
				$xNode =bXml::ToXml($mName);
				$oNodeChild =dom_import_simplexml($xNode);
				
				$oNode =dom_import_simplexml($this);
				$oDom =$oNode->ownerDocument;

				$oChild =$oDom->importNode($oNodeChild, true);
				$oNode->appendChild($oChild);
				
			} else {
				
				parent::AddChild($mName, $mData, $sNamespace);
			}
			
			return $this;
		}
		
		/// <summary>
		/// 	Allows the addition of a Comment node
		/// </summary>
		/// <param type="string" name="sData">Any string data</param>
		/// <returns type="this" />
		public function AddComment($sData) {

				$oNode =dom_import_simplexml($this);
				$oDom =$oNode->ownerDocument;
				
				$oComment =$oDom->createComment($sData);
				$oNode->appendChild($oComment);
				
				return $this;
		}
		
		/// <summary>
		///  returns a new object based off of the current object
		/// </summary>
		/// <returns type="bXml" />
		public function CloneNode() {
			
			return new bXml($this->asXml()); // the ->asXML prevents cloning parent and ancestor node	
		}
		
		/// <summary>
		///  Inserts an XML type before a child node
		/// </summary>
		/// <param type="mixed" name="mNode">
		///  The node of any xml type or stream to add to the current node
		/// </param>
		/// <param type="bXml|bSimpleXml" name="xReferenceNode" optional="true">
		///  The child node to insert the node before. If this is not passed in
		///  then the <param name="mNode" /> param will be inserted before the
		///  CURRENT node.
		/// </param>
		/// <returns type="bSimpleXml" />
		public function InsertBefore($mNode, IbXml $xReferenceNode =null) {

			$xThisNode =($xReferenceNode ==null ? $this : $xReferenceNode);
			
			$oNode =dom_import_simplexml($xThisNode);
			$oDom =$oNode->ownerDocument;
			
			$xNode =bXml::ToXml($mNode);
			$oInsert =dom_import_simplexml($xNode);
			
			$oInsertBefore =$oDom->importNode($oInsert, true);
			$oNode->parentNode->insertBefore($oInsertBefore, $oNode);
			
			return $this;
		}
		
		/// <summary>
		///  The parent node of the current node
		/// </summary>
		/// <returns type="bSimpleXml" />
		public function ParentNode() {

			$d =dom_import_simplexml($this);
			$oReturn =simplexml_import_dom($d->parentNode, __CLASS__);
				
			return $oReturn;
		}
		
		/// <summary>
		///  Removes a child node from the current node
		/// </summary>
		/// <param type="bXml|bSimpleXml">
		///  the child node to remove
		/// </param>
		/// <returns type="bSimpleXml">
		///   The current node with the child removed
		/// </returns>
		public function RemoveChild(IbXml $xNode) {
			
			$oNode =dom_import_simplexml($xNode);
			
			$oParent =$oNode->parentNode;
			$oParent->removeChild($oNode);
			
			return $this;
		}
		
		/// <summary>
		///  Removes the current node and returns the parent
		/// </summary>
		/// <returns type="bSimpleXml">The parent node</returns>
		public function RemoveNode() {
			
			$oNode =dom_import_simplexml($this);
			
			$oParent =$oNode->parentNode;
			$oParent->removeChild($oNode);
			
			return simplexml_import_dom($oParent, __CLASS__);
		}
		
		/// <summary>
		///   Swaps out the child node with the new node passed in
		/// <summary>
		/// <param type="bXml|bSimpleXml" name="mNodeOld">
		///   The child node to swap out
		/// </param>
		/// <param type="mixed" name="bNodeNew">
		///   Any Xml Type or stream to replace the child node with
		/// </param>
		/// <param type="bool" name="bWith" optional="true">
		///   a switch to tell if the child node is the current node, should
		///   really only be called from the <function name="ReplaceWith" /> function.
		/// </param>
		/// <returns type="bSimpleXml">
		///   The current node with the replaced child node in place
		/// </returns>
		public function ReplaceChild(IbXml $xNodeOld, $mNodeNew, $bWith =false) {
			
			$xNodeNew =bXml::ToXml($mNodeNew);
			
			$oNodeOld =dom_import_simplexml($xNodeOld);
			$oNodeNew =dom_import_simplexml($xNodeNew);
			
			$oNode =dom_import_simplexml($this);
			$oDom =$oNode->ownerDocument;
			
			$oNodeReplacement =$oDom->importNode($oNodeNew, true);
			
			$oNode =($bWith ? $oNode->parentNode : $oNode);
			
			$oNode->replaceChild($oNodeReplacement, $oNodeOld);
			
			return $this;
		}
		
		/// <summary>
		///   Swaps out the current node with the new node passed in
		/// <summary>
		/// <param type="mixed" name="mNode">
		///   The xml node (of any xml type or stream)
		/// </param>
		/// <returns type="bSimpleXml">
		///   The replaced node as the current node in the document
		/// </returns>
		public function ReplaceWith($mNode) {
			
			return $this->ReplaceChild($this, $mNode, true);
		}
		
		/// <summary>
		///   Returns the root or document node
		/// </summary>
		/// <returns type="bSimpleXml" />
		public function RootNode() {
			
			return simplexml_import_dom(
				dom_import_simplexml($this)->ownerDocument, 
				__CLASS__
			);
		}
		
		/// <summary>
		/// 	Pass in a stylesheet and it will be transformed aginst the full xml of this object
		/// </summary>
		/// <param type="mixed" name="mXsl">Any XML type can be passed in from a string to bXml</param>
		/// <param type="array" name="aArgument" optional="true">
		/// 	Need to pass in the form array(<key>, <value>, <namespace>). So this is an array of arrays
		/// </param>
		/// <returns type="DomDocument" />
		public function TransformWith($mXsl, array $aArgument =null) {
			
			$this->LoadStylesheet(new bXml($mXsl), $aArgument);

			$oDom =dom_import_simplexml($this)->ownerDocument;
			$oTransformed =$this->ObjectProcessor()->transformToDoc($oDom);

			return $oTransformed;
		}
		
		/// <summary>
		///  The XML node to wrap around the current node, will append current node
		///  to the end of any children of the passed in node
		/// </summary>
		/// <param type="mixed" name="mNodeWrap">
		///   Any valid XML node type or stream
		/// </param>
		/// <returns type="bSimpleXml">The current node as WRAPED by the new node</returns>
		public function WrapWith($mNodeWrap) {
			
			$oNode =dom_import_simplexml($this);
			$oDom =$oNode->ownerDocument;
			
			$xNodeWrap =bXml::ToXml($mNodeWrap);
			$oNodeWrap =dom_import_simplexml($xNodeWrap);
			
			$oWrap =$oDom->importNode($oNodeWrap, true);

			$oNode->parentNode->insertBefore($oWrap, $oNode);
			$oWrap->appendChild($oNode);
			
			return $this;
		}
		
		/// <summary>
		/// 	returns the current node name, alias for <method name="getName" />
		/// </summary>
		public function NodeName(){
			return dom_import_simplexml($this)->nodeName;
		}
		
		/// <summary>
		///   Returns the type of the node currently being evaluated
		/// <summary>
		/// <returns type="int">Codes are based on the DOM Xml Type codes</returns>
		public function NodeType() {

			return dom_import_simplexml($this)->nodeType;
		}
		
		/// <summary>
		///  Set or get the value of the current node
		/// </summary>
		/// <param type="string" name="sValue" optional="true">
		///   The value to set the current node to. When no value is passed in,
		///    it returns the current value.
		/// </param>
		/// <returns type="string">The value of the node</returns>
		public function NodeValue($sValue =null) {
			
			if($sValue ==null) {
				
				return dom_import_simplexml($this)->nodeValue;
			} else {
			
				dom_import_simplexml($this)->nodeValue =$sValue;
				return $this;
			}
		}
		
		/// <summary>
		///   Returns the first node or false if the node is not valid
		///   of a child node.
		/// <summary>
		/// <returns type="bSimpleXml|false" />
		public function FirstChild() {
			
			$oNode =dom_import_simplexml($this)->firstChild;
			if($oNode->nodeType ==3) { // is a TextNode
				
				$oNode =$oNode->parentNode;
			}
			
			if($oNode ==null) {

				$oThis =false;
			} else {

				$oThis =simplexml_import_dom($oNode, __CLASS__);
			}
			return $oThis;
		}
		
		/// <summary>
		///   Returns the last node or false if the node is not valid
		///   of a child node.
		/// <summary>
		/// <returns type="bSimpleXml|false" />
		public function LastChild() {
			
			$oNode =dom_import_simplexml($this)->lastChild;
			if($oNode->nodeType ==3) { // is a TextNode
				
				$oNode =$oNode->parentNode;
			}
			
			if($oNode ==null) {

				$oThis =false;
			} else {

				$oThis =simplexml_import_dom($oNode, __CLASS__);
			}
			return $oThis;
		}
		
		/// <summary>
		///   Returns the preceeding sibling node or false if you are at the first node
		///   of a child node.
		/// <summary>
		/// <returns type="bSimpleXml|false" />
		public function PreviousSibling() {
				
				$oNode =dom_import_simplexml($this)->previousSibling;
				
				if($oNode ==null) {

					$oThis =false;
				} else {

					$oThis =simplexml_import_dom($oNode, __CLASS__);
				}
				return $oThis;
		}
		
		/// <summary>
		///   Returns the next sibling node or false if you are at the last node
		///   of a child node.
		/// <summary>
		/// <returns type="bSimpleXml|false" />
		public function NextSibling() {
			
			$oNode =dom_import_simplexml($this)->nextSibling;
			
			if($oNode ==null) {
				
				$oThis =false;
			} else {
				
				$oThis =simplexml_import_dom($oNode, __CLASS__);
			}
			return $oThis;
		}
		
		/// <summary>
		/// 	Returns either the node at the positon specified or gives the position of the current node
		/// </summary>
		/// <param type="integer" name="nPosition" optional="true">The position of the node to return</param>
		/// <returns type="bSimpleXml">The node at the postion specified</returns>
		/// <returns type="integer">The current node</returns>
		public function Position($nPosition =null) {
			
			if($nPosition ==null) {
				
				$n =0;
				$oNode =dom_import_simplexml($this);
				$sThisName =$oNode->nodeName;
				
				while(!!$oNode) {
					$sNodeName =$oNode->nodeName; // must be before, otherwise node might be null after previous siblin move
					$oNode =$oNode->previousSibling;
					
					if($sNodeName ==$sThisName) { $n++; }
				}
				
				$mReturn =$n;
			} else {
				
				$oNode = dom_import_simplexml($this)->parentNode->childNodes->item($nPosition -1);
				$mReturn =simplexml_import_dom($oNode, __CLASS__);
			}
			
			return $mReturn;
		}
		
		/// <summary>
		///   Returns the namespace prefix of the node id available.
		/// </summary>
		public function Prefix() {
			
			return dom_import_simplexml($this)->prefix;
		}
		
		/// <summary>
		/// 	Generates an Xpath of the current location. Will walk backwards from any passed node.
		/// </summary>
		/// <param type="bSimpleXml" name="xNode" optional="true">The node to find the path from</param>
		/// <returns type="string">The XPath</returns>
		public function PathFinder(IbXml $xNode =null, $bFullPath =false) {
			
			$sPath ='';
			$oNode =dom_import_simplexml((!!$xNode ? $xNode : $this));
				
			while(!!$oNode && !($oNode instanceof DomDocument)) {
				$xNode =simplexml_import_dom($oNode);
				$aNamespace =$this->ObjectNamespace($xNode);
				
				$sPrefix =(($s =$oNode->namespaceURI) !='' ? $aNamespace[$s].':' : ''); 
				$sNodeName =$oNode->nodeName;
				$nPosition =count(
					(array)$xNode->xpath('preceding-sibling::*[name() = "'.$sNodeName.'"]')
				) +1;
			
				$sPath ='/'.$sPrefix.$sNodeName.($nPosition > 1 || $bFullPath ? '['.$nPosition.']' : '').$sPath;
				
				$oNode =$oNode->parentNode;
			}
			
			return $sPath;
		}
		
		public function AsArray() {
			static $nStack =0;
			$sFunction =__FUNCTION__;
			$aXml =array();
			
			foreach($this as $sKey=>$mValue) {
				
				$sValue =((string)$mValue);
				if(isset($aXml[$sKey])) {
					
					$aXml[$sKey] =array_merge($aXml[$sKey], (array)$sValue);
				} else {
					
					$nChildType =dom_import_simplexml($mValue)->firstChild->nodeType;
					
					if($sValue !='' && $nChildType !=1) { // element
						
						$aXml[$sKey] =(array)$sValue;
					} elseif($nChildType !=1) {
					
						$aXml[$sKey] =(array)$sValue;
					}
				}
				
				foreach($mValue->Children() as $sKey2 =>$mValue2) {
					
					$nStack++;
					$aXml[$sKey][$sKey2] =$mValue2->$sFunction();
					$nStack--;
				}
				
				foreach($mValue->Attributes() as $sKey3 =>$mValue3) {
					
					$aXml[$sKey]['@'.$sKey3] =(string)$mValue3;
				}
			}
			
			if($nStack ==0) {
				$sArgument ='';
				$aArgument =func_get_args();
				
				if(count($aArgument) > 0) { $sArgument =array_pop($aArgument); }
				
				if($sArgument =='!') {
					$aReturnXml[$this->getName()] =$aXml;
					foreach($this->Attributes() as $sKey4 =>$mValue4) {

						$aReturnXml[$this->getName()]['@'.$sKey4] =(string)$mValue4;
					}
				
					$aXml =$aReturnXml;
				}
			}

			return $aXml;
		}
		
		public function AsJson() {
			
			return json_encode($this->AsArray());
		}
		
		/// <summary>
		/// 	Returns as a dom document or dom element
		/// </summary>
		/// <param type="constant" name="cType" optional="true">
		/// 	Determine if you would want to return a Document or Element.
		/// </param>
		/// <returns type="DomDocument|DomElement" />
		public function AsDom($cType =bXml::DOM_DOCUMENT) {
			
			if($cType ==bXml::DOM_DOCUMENT) {
				
				return dom_import_simplexml($this)->ownerDocument;
			} else {
			
				return dom_import_simplexml($this);
			}
		}
	}
	
	/**
	 * <summary>
	 *  The XML class that is passed around the application. This is based off of simpleXML in that you 
	 *  can do anything with it that you can with simplexml just some more things. Like you can add
	 *  child objects of XML and you can add CData and Comment nodes very easliy. It also handles some
	 *  counting and other internal XML conversion things (like ToArray() and Transform so you) can 
	 *  pretty much use this in place of all the DOM, SimpleXml, Xpath and XSLTprocessor classes.
	 * </summary>
	 */
	class bXml extends ArrayObject implements IteratorAggregate, IbXml {
		private static $nMajor =1;
		private static $nMinor =0;
		private static $sRevision ="0000";
		
		private $xXml;
		
		const DOM_DOCUMENT		='(dom)[docu]{4}ment';
		const DOM_ELEMENT		='(dom)e.[(.|e)]ment';
		const IS_ATTRIBUTE 		=true;
		const RETURN_XML 		=true;
		const NODE_ARRAY 		='/(?:node[ _-]ar{2}ay)/i';
		const NO_DECLARATION	='/n(o)_[d]ecl(a)r$2tion/';
		
		const XML_ELEMENT_NODE 			=XML_ELEMENT_NODE;
		const XML_TEXT_NODE 			=XML_TEXT_NODE;
		const XML_CDATA_SECTION_NODE	=XML_CDATA_SECTION_NODE;
		const XML_COMMENT_NODE			=XML_COMMENT_NODE;
		
		/// <summary>
		///   returns the version of this class for resource management
		/// </summary>
		/// <returns type="string">The version</returns>
		public static function version() { return self::$nMajor.'.'.self::$nMinor.'.'.self::$sRevision; }
			
		/// <summary>
		/// 	Allows the input of any XML type and sets up the bSimpleXml Insides
		/// </summary>
		/// <param type="mixed" name="mXml">Any type of Xml</param>
		public function __construct($mXml =null) {
			
			$this->xXml =self::ToXml($mXml);
		}
		
		/// <summary>
		///   Allows one to staticlly instanciate a new bXml object
		///   So the new keyword is not allowed
		/// </summary>
		/// <param type="mixed" name="mXml" optional="true">
		///    Any XML type as well as any stream that resolves as XML
		///    Note that when null is passed in a node of "<empty />" will be
		///    created automatically
		/// </param>
		/// <returns type="bXml">A NEW bXml object</returns>
		public static function Load($mXml =null){
			
			return new bXMl($mXml);
		}
		
		/// <summary>
		/// 	sets the iterarators over the internal bSimpleXml object
		/// </summary>
		/// <returns type="object">The iterators</returns>
		public function getIterator() {

			return new SimpleXMLIterator($this->xXml->AsXml());
		}
		
		/// <summary>
		/// 	Passes the bSimpleXml property requests along
		/// </summary>
		/// <params type="string" name="sChild">The name of the bSimpleXml node to lookup</params>
		/// <returns type="bSimpleXml" />
		public function __get($sChild) {
			
			return $this->xXml->{$sChild};
		}
		
		/// <summary>
		/// 	Passes the bSimpleXml property requests along and sets it
		/// </summary>
		/// <params type="string" name="sChild">The name of the bSimpleXml node to set</params>
		/// <params type="string" name="sData">The value to set to</params>
		/// <returns type="bSimpleXml" />
		public function __set($sChild, $sData) {
			
			return $this->xXml->{$sChild} =$sData;
		}
		
		/// <summary>
		/// 	Passes the bSimpleXml method requests along
		/// </summary>
		/// <params type="string" name="sMethod">The name of the bSimpleXml method to use</params>
		/// <params type="array" name="sMethod">The arguments of the bSimpleXml object</params>
		/// <returns type="bSimpleXml" />
		public function __call($sMethod, $a) {
			
			return call_user_func_array(array($this->xXml, $sMethod), $a);
		}
		
		/// <summary>
		///  Allows access to the attributes of the bXml class
		/// </summary>
		/// <param type="string|int" name="mIndex">
		///    The index or the name of the attibute one is looking up
		/// </param>
		/// <returns type="string">The value of the attribute</returns>
		public function offsetGet($mIndex) {
			
			return $this->xXml[$mIndex];
		}
		
		/// <summary>
		///   Allows access to the attributes of the bXml class
		/// </summary>
		/// <param type="string|int" name="mIndex">
		///   The attribute name or index to change or set
		/// </param>
		/// <param type="string|int" name="mData">
		///   The value of the attribute is going to be set to.
		/// </param>
		public function offsetSet($mIndex, $mData) {
			
			return $this->xXml[$mIndex] =$mData;
		}
		
		public function AsArray() {
			
			return $this->xXml->asArray('!');
		}
		
		/// <summary>
		/// 	Takes any xml type pr resovlable stream and converts to bSimpleXml type
		/// </summary>
		/// <param type="mixed" name="mXml">
		///    The XML or stream
		///    <example> A stream example is: file:///XmlFileHere.xml </example>
		/// </param>
		public static function ToXml($mXml) {
			
			if(is_string($mXml)) {
				
				if(!preg_match('/(<\/|\/>)/', $mXml)) {
					
					$aStreams =stream_get_wrappers();
					array_walk($aStreams, create_function('&$s', '$s =$s."://";'));
					
					preg_match('/([A-Z]+:\/\/)/i', $mXml, $aMatch);
					$sMatch =(empty($aMatch) ? '' : $aMatch[1]);
					
					if(file_exists($mXml) || in_array($sMatch, $aStreams)) {
						
						$mXml =file_get_contents($mXml);
					} else {
						
						$mXml ='<xml>'.$mXml.'</xml>'; //auto wrapping.
					}
				}
			}
			
			switch(true){
				
				case $mXml ==null:
					$oXml =new bSimpleXml('<empty />');
				break;
				case($mXml instanceof bSimpleXml):
					
					$oXml =$mXml;
				break;

				case($mXml instanceof SimpleXmlElement):
					$oXml =@simplexml_import_dom(dom_import_simplexml($oXml), 'bSimpleXml');
				break;
				
				case($mXml instanceof DOMDocument):
					
					$mXml =$mXml->documentElement; //Drop
				case($mXml instanceof DOMElement):
					
					$oXml =@simplexml_import_dom($mXml, 'bSimpleXml');
				break;

				case(is_string($mXml)):
					$oXml =@simplexml_load_string($mXml, 'bSimpleXml');
					
					if($oXml ===false && strpos($mXml, '<') !==false) {
						
						throw new bXmlException(
							'The input could not be converted to an bXml object. Asumed Xml. ',
						bXmlException::INVALID_CONVERSION_STRING);
					} elseif($oXml ===false && strpos($mXml, '<') ===false) {
						
						throw new bXmlException(
							'The input could not be converted to an bXml object. Asumed Qname. ',
						bXmlException::INVALID_CONVERSION);
					}
				break;
				
				case(is_array($mXml)):

					$mXml =new bArray($mXml); //Drop
				case($mXml instanceof bXml):
				case($mXml instanceof bArray):

					$oXml =@simplexml_load_string($mXml->AsXml(), 'bSimpleXml');
				break;
					
				case($mXml instanceof XmlWriter):
					$oXml =@simplexml_load_string($mXml->outputMemory(), 'bSimpleXml');
					if($oXml ===false) {
						
						throw new bXmlException(
							'The input could not be converted to an bXml object. Asumed XmlWriter was valid. ',
						bXmlException::INVALID_CONVERSION);
					}
				break;
					
				default:
					throw new bXmlException(
						'A valid XML type has not been passed. Type of ['.gettype($oXml).'] has been passed. ',
					bXmlException::INVALID_CONVERSION);
			}
			
			return $oXml;
		}
	}
	
?>
<?php //include_once(realpath("../functions/bEasyResourceManager.php")); 
return; ?>
<bResourceManager version="1.0">
	<summary 
		name="bXml"
		version="1.0" 
		checksum="none" 
		signed="http://www.art-k-tec.com/libs/signatures/bXml"
		copyright="2007 art-k-tec systems, llc"
	>
		First resource management package. It's intended to be generic so it can be used in a wide
		variety of PHP projects.
	</summary>
	<summary 
		name="bSimpleXml"
		version="1.0" 
		checksum="none" 
		signed="http://www.art-k-tec.com/libs/signatures/bSimpleXml"
		copyright="2007 art-k-tec systems, llc"
	>
		First resource management package. It's intended to be generic so it can be used in a wide
		variety of PHP projects.
	</summary>
</bResourceManager>